<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>书籍</title>
</head>
<body>
    <p> 你好</p>
    <button id="fetchButton">搜索</button>
    <div id="result"></div>

</body>
</html>

<script>
    document.getElementById('fetchButton').addEventListener('click', function() {
        // 使用 fetch API 发送 GET 请求
        fetch('/your-api-endpoint')
            .then(response => {
                // 检查响应是否成功
                if (!response.ok) {
                    throw new Error('Network response was not ok ' + response.statusText);
                }
                return response.json(); // 将响应转换为JSON
            })
            .then(result => {
                // 处理成功的响应
                console.log('Code:', result.code);
                console.log('Message:', result.message);
                console.log('Data:', result.data);

                // 显示结果到页面上
                const resultDiv = document.getElementById('result');
                resultDiv.innerHTML = `
        <p>Code: ${result.code}</p>
        <p>Message: ${result.message}</p>
        <pre>Data: ${JSON.stringify(result.data, null, 2)}</pre>
      `;
            })
            .catch(error => {
                // 处理错误
                console.error('Error:', error);
                const resultDiv = document.getElementById('result');
                resultDiv.innerHTML = `<p>Error: ${error.message}</p>`;
            });
    });
</script>